package com.sinosoft.perfect.system.chooseComponent.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

import com.sinosoft.perfect.common.system.BaseAction;
import com.sinosoft.perfect.system._.po.TUser;
import com.sinosoft.perfect.system._user.service.IUserService;
import com.sinosoft.perfect.system.chooseComponent.dataFormat.IChooseUserGridDataFormat;

@SuppressWarnings("serial")
public class ChooseUserAction extends BaseAction {

	private IChooseUserGridDataFormat ichooseUserGridDataFormat;
	private IUserService iuserService;
	private TUser tuser;
	
	public IChooseUserGridDataFormat getIchooseUserGridDataFormat() {
		return ichooseUserGridDataFormat;
	}
	public void setIchooseUserGridDataFormat(
			IChooseUserGridDataFormat ichooseUserGridDataFormat) {
		this.ichooseUserGridDataFormat = ichooseUserGridDataFormat;
	}
	public IUserService getIuserService() {
		return iuserService;
	}
	public void setIuserService(IUserService iuserService) {
		this.iuserService = iuserService;
	}
	public TUser getTuser() {
		return tuser;
	}
	public void setTuser(TUser tuser) {
		this.tuser = tuser;
	}

	
	public String queryUserInfoByUserIds() throws IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		String resultXml = null;
		try {
			List<TUser> tus = iuserService.selectTUsersInfoByUserids(request.getParameter("userIds"));
			resultXml = ichooseUserGridDataFormat.dataFormatUserGrid(tus);

		} catch (SQLException e) {
			e.printStackTrace();
			session.put("exceptionInfoClass", e);
			return "exceptionOperateAction";
		}
		PrintWriter out = response.getWriter();
		out.print(resultXml);
		out.flush();
		out.close();
		return null;
	}
	
	public String queryUserInfoByUser() throws IOException {
		response.setContentType("text/xml;charset=UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		String resultXml = null;
		try {
			List<TUser> tus = iuserService.selectTUser(tuser);
			resultXml = ichooseUserGridDataFormat.dataFormatUserGrid(tus);

		} catch (SQLException e) {
			e.printStackTrace();
			session.put("exceptionInfoClass", e);
			return "exceptionOperateAction";
		}
		PrintWriter out = response.getWriter();
		out.print(resultXml);
		out.flush();
		out.close();
		return null;
	}
}
